//vuex统一管理数据
import { reqCategoryListData, reqGetBannerListDate } from '../../api/index';

const state = {
    CategoryListData: [],
    BannerListData: [],
};

const actions = {
    async getCategoryListData({ commit }) {
        const result = await reqCategoryListData();
        if (result.code === 200) {
            // console.log(result.data);
            return commit('SAVE_CATEGORY_LIST_DATA', result.data);
        } else {
            return result.message;
        }
    },
    async getBannerListData({ commit }) {
        const result = await reqGetBannerListDate();
        if (result.code === 200) {
            commit('SAVE_BANNER_LIST_DATA', result.data);
        } else {
            return result.message;
        }
    },
};

const mutations = {
    SAVE_CATEGORY_LIST_DATA(state, CategoryListData) {
        state.CategoryListData = CategoryListData;
    },
    SAVE_BANNER_LIST_DATA(state, BannerListData) {
        state.BannerListData = BannerListData;
    },
};

const getters = {};

export default {
    namespaced: true, //开启命名空间
    state,
    actions,
    mutations,
    getters,
};
